package com.zh.note.huawei.onehundred.热点网络统计;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author: zhanghuan
 * @date: 2023/9/3 11:25
 * @description: create it
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Map<String, Integer> map = new HashMap<>();
        while (sc.hasNext()) {
            String line = sc.nextLine();
            solution(line, map);
        }

    }

    private static void solution(String line, Map<String, Integer> map) {
        if (line.length() > 1) {
            map.put(line, map.getOrDefault(line, 0) + 1);
        } else if (!line.isEmpty()) {
            int n = Integer.parseInt(line);
            List<Map.Entry<String, Integer>> list = map.entrySet().stream().sorted(new Comparator<Map.Entry<String, Integer>>() {
                @Override
                public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                    return o2.getValue().compareTo(o1.getValue());
                }
            }).collect(Collectors.toList());
            for (int i = 0; i < n; i++) {
                System.out.print(list.get(i).getKey());
                if (i != n - 1) {
                    System.out.print(",");
                }
            }
        }


    }
}
